package chat.client;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.util.Scanner;

public class clientold{

	public static void main (String[] args){
		Scanner reader = new Scanner(System.in);
		BufferedWriter out = null;
		BufferedReader in = null;
		Socket socket = null;
		Scanner keyboardReader = new Scanner(System.in);
		try {
			socket = new Socket("localhost",8099);
			System.out.print("username :");
			String u = keyboardReader.nextLine();
			System.out.println();
			System.out.print("password :");
			String p = keyboardReader.nextLine();
			
			out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
			in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			out.write(u);
			out.write('\n');
			out.write(p);
			String str = null;
			String talk = null;
			while((str = in.readLine()) != null){
				if(str.equals("bye")){
					System.out.println("Exiting the Chat");
					System.exit(0);
				}
				talk = keyboardReader.nextLine();
				out.write(talk);
				out.write('\n');
			}
		}catch (Exception e){
			e.printStackTrace();
		}	finally	{
			if(out != null){
				try {
					out.close();
				}catch(Exception e) {
				}
			}
			if(socket != null){
				try{
					socket.close();
				}catch(Exception e) {
				}
			}			
		}
		reader.close();
	}
}